/* eslint-disable */
import Vue from 'vue'
import axios from 'axios'

export const client = 20 // pad ios

// http://221.122.129.57/debug/pet
// ws://221.122.129.57/debug/pet

const baseURL = process.env.NODE_ENV === 'production'
  ? 'http://phoenix.facethink.com/release/pet'
  : 'http://pxtest.facethink.com/debug/pet'

export const wsBaseURL = process.env.NODE_ENV === 'production'
  ? 'ws://phoenix.facethink.com/release/pet'
  : 'ws://pxtest.facethink.com/debug/pet'

export function createAxiosObj (classInfo) {
  const request = axios.create({
    baseURL,
    headers: {
      'T-px-Validate-Token': classInfo.token,
      'T-px-Post-ID': String(+new Date()),
      'T-px-Trace-ID': String(+new Date()),
      'T-px-Lesson-Num': classInfo.lessonNum, // 39
      'T-px-Class-ID': classInfo.classID,
      'T-px-Client-Type': client, //  //1 20 30
      'Content-Type': 'application/json;charset=utf-8'
    }
  })

  request.interceptors.response.use((response) => {
    // 对响应数据做点什么
    return response.data
  }, (error) => {
    // 对响应错误做点什么
    return Promise.reject(error)
  })

  Vue.use((Vue) => {
    Vue.prototype.$rq = request
  })
}

export function ajax (Vue) {
  Vue.prototype.$ajax = axios
}

export default baseURL
